﻿/**
*    Copyright (C) 2008  Chase Kernan 
*    chase.kernan@gmail.com
*
*    This program is free software: you can redistribute it and/or modify
*    it under the terms of the GNU General Public License as published by
*    the Free Software Foundation, either version 3 of the License, or
*    (at your option) any later version.
*
*    This program is distributed in the hope that it will be useful,
*    but WITHOUT ANY WARRANTY; without even the implied warranty of
*    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
*    GNU General Public License for more details.
*
*    You should have received a copy of the GNU General Public License
*    along with this program.  If not, see <http://www.gnu.org/licenses/>.
* 
**/

package com.chasekernan.hxnova.componenteditor.details;

import com.chasekernan.hxnova.componenteditor.ComponentEditorPanel;
import com.chasekernan.hxnova.componenteditor.DetailsPanel;
import com.chasekernan.hxnova.core.components.Engine;
import org.aswing.JAdjuster;
import org.aswing.JCheckBox;

class EnginePanel extends DetailsPanel {
    
    private var ramscoopInput : JCheckBox;
    private var combatSpeedInput : JAdjuster;
    private var efficiencyInputs : IntHash<JAdjuster>;
    
    public function new() {
        super();
        
        combatSpeedInput = DetailsPanel.createIntAdjuster(Engine.COMBAT_SPEED_MIN, Engine.WARP_MAX);
        addRowHaxe(createLeftLabel("Combat Speed"), combatSpeedInput, null);
        
        ramscoopInput = new JCheckBox("Is Ramscoop?");
        addRowHaxe(ramscoopInput, null, null);
        
        allInputs = [combatSpeedInput, ramscoopInput];
        
        efficiencyInputs = new IntHash();
        for (warp in Engine.WARP_MIN...(Engine.WARP_MAX + 1)) {
            var adj = DetailsPanel.createIntAdjuster( -800, 800);
            
            efficiencyInputs.set(warp, adj);
            addRowHaxe(createLeftLabel("Warp " + warp), adj, null);
            allInputs.push(adj);
        }
    }
    
    public override function loadFromComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var engine = cast(ComponentEditorPanel.INSTANCE.editedComponent, Engine);
        
        ramscoopInput.setSelected(engine.isRamscoop);
        combatSpeedInput.setValue(engine.combatSpeed);
        
        for (warp in Engine.WARP_MIN...(Engine.WARP_MAX + 1)) {
            efficiencyInputs.get(warp).setValue(engine.getEfficiency(warp));
        }
    }
    
    public override function saveToComponent() {
        if (ComponentEditorPanel.INSTANCE.editedComponent == null) return;
        
        var engine = cast(ComponentEditorPanel.INSTANCE.editedComponent, Engine);
        
        engine.isRamscoop = ramscoopInput.isSelected();
        engine.combatSpeed = combatSpeedInput.getValue();
        
        for (warp in Engine.WARP_MIN...(Engine.WARP_MAX + 1)) {
            engine.setEfficiency(warp, efficiencyInputs.get(warp).getValue());
        }
    }
    
}